package com.bai.localshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bai.localshop.pojo.entity.AddressBook;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface AddressBookMapper extends BaseMapper<AddressBook> {

    @Update("UPDATE address_book SET is_default = 0 WHERE user_id = #{userId} AND is_default = 1")
    void clearDefaultAddress(@Param("userId") Long userId);

    @Update("UPDATE address_book SET is_default = 1 WHERE id = #{id} AND user_id = #{userId}")
    int setDefaultAddress(@Param("id") Long id, @Param("userId") Long userId);
}